package com.example.tests.User;

import java.util.Arrays;
import java.util.Collection;

import com.example.model.User;
import com.example.tests.BaseTest;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;


@RunWith(Parameterized.class)
public class ParametrizedUserTest extends BaseTest {

    private User user;
    private String errorMessage;
    private int type;

    public ParametrizedUserTest(User user, String errorMessage, int type) {
        this.user = user;
        this.errorMessage = errorMessage;
        this.type = type;
    }


    @Parameterized.Parameters
    public static Collection<Object[]> data() {
        User user1 = User.createValidUser();
        user1.name = "";

        User user2 = User.createValidUser();
        user2.email = "not_valid_email";

        User user3 = User.createValidUser();
        user3.passwordConfirmation = "111";

        return Arrays.asList(new Object[][]{
                {user1, "This field is required", 1},
                {user2, "Please enter a valid e-mail address", 2},
                {user3, "Both values should be the same", 3}
        });
    }


    @Test
    public void registerUserErrorsTest() {
        goToHomePage()
            .loginWithValidCredentials("admin", "admin")
            .goToUsers()
            .registerUser(user)
            .checkErrorMessage(errorMessage, type)
            .logout();
    }


}
